const http = require('http');
const fs =require('fs');
const path = require('path');

http.createServer((request, response) => {
    if(request.url === '/') {
        fs.readFile(path.join(__dirname, 'index.html'), 'utf8', (err, chunk) => {
            if(err) {
                response.end(chunk);
            }else{
                response.end(chunk);
            }
        })
    }else  if(request.url == '/http.html') {
        const staic =  path.join(__dirname, request.url);
        fs.readFile(staic, 'utf8', (err, chunk) => {
            if(err) {
                response.end(chunk);
            }else{
                response.end(chunk);
            }
        })
    }else if(request.url == '/def_img.jpg') {
        const staic =  path.join(__dirname, request.url);
        fs.readFile(staic, (err, chunk) => {
            if(err) {
                response.end(chunk);
            }else{
                console.log(chunk);
                response.end(chunk);
            }
        })
    }else if(request.url == '/style.css') {
        const staic =  path.join(__dirname, request.url);
        fs.readFile(staic, (err, chunk) => {
            if(err) {
                response.end(chunk);
            }else{
                response.end(chunk);
            }
        })
    }
}).listen(3000, '127.0.0.1', ()=>{
    console.log('server running ...')
});
